import { GStatic } from "../../../Core/Manager/DataPool";

const { ccclass } = cc._decorator;
@ccclass
export class SSkillData extends GStatic {
	public parse(obj: any): boolean {
		for (let i = 0; i < obj.data.length; i++) {
			let raw = GStatic.addonRaw<SSkillDataRaw>(obj.data[i]);
			this._data.set(raw.id, raw);
		}
		return true;
	}

	/**获取英雄所有技能 */
	public getHeroSkillData(heroid: number) {
		var skill = this._data.values();
		var heroSkill = [];
		skill.forEach((v: SSkillDataRaw) => {
			v.who.forEach((w: number) => {
				if (w == heroid) {
					heroSkill.push(v);
				}
			})
		})
		return heroSkill
	}

	/**获取英雄可以使用的技能 */
	public getHeroUseSkill(heroid: number, lv: number) {
		var skill = this._data.values();
		var heroSkill = [];
		skill.forEach((v: SSkillDataRaw) => {
			v.who.forEach((w: number) => {
				if (w == heroid) {
					if (v.unlocking == 0) {
						heroSkill.push(v.id);
					} else if (lv >= v.unlocking) {
						heroSkill.push(v.id);
					}
				}
			})
		})
		return heroSkill
	}
}